#include<bits/stdc++.h>
using namespace std;
void solve(string s,int x){
    int HH_1,MM_1,second1_1,second2_1;
    int HH_2,MM_2,second1_2,second2_2;
    char *cha = (char *)s.data();
    sscanf(cha,"%d:%d:%d,%d --> %d:%d:%d,%d",&HH_1,&MM_1,&second1_1,&second2_1,&HH_2,&MM_2,&second1_2,&second2_2);
    int start = (((HH_1 * 60) + MM_1) * 60) * 1000 + (second1_1 * 1000 + second2_1);
    int end = (((HH_2 * 60) + MM_2) * 60) * 1000 + (second1_2 * 1000 + second2_2);
    start += x;
    end += x;
    //cout << "start=" << start << " " << "end=" << end << endl;
    printf("%02d:%02d:%02d,%03d --> ",start/3600000,start/60000%60,start%60000/1000,start%1000);
    printf("%02d:%02d:%02d,%03d\n",end/3600000,end/60000%60,end%60000/1000,end%1000);

}
int main(){
    string s;
    string context[1000];
    int k = 0;
    while(getline(cin,s)){
        if(s == "#")break;
        context[k++] = s;
    }
    int TIME;
    cin >> TIME;
    for(int i=0;i<k;i++){
        bool flag = false;
        for(int j=0;j<context[i].length();j++){
            if(context[i][j] == '>'){
                flag = true;
                break;
            }
        }
        if(!flag)cout << context[i] << "\n";
        else solve(context[i],TIME);
    }
    cout << "#";

    return 0;
}